package com.encon.projecttracker.server.servlet;

import java.util.List;

import javax.servlet.ServletException;

import org.apache.log4j.Logger;

import com.encon.projecttracker.rpc.Query;
import com.encon.projecttracker.rpc.beans.CompaniesDTO;
import com.encon.projecttracker.rpc.beans.TestDTO;
import com.encon.projecttracker.server.messages.Messages;
import com.encon.projecttracker.server.services.QueryService;


/**
 * 
 * Spring based query servlet.
 *
 * @author tom(at)wamonline.org.uk
 *
 */
public class QueryServlet extends AbstractServlet implements Query{
    	
    private static final long serialVersionUID = 1L;
	
	private transient QueryService queryService;
	
	private transient Logger log = Logger.getLogger(QueryServlet.class);
	public void init() throws ServletException {
		super.init();
		queryService = (QueryService)applicationContext.getBean("queryService"); //$NON-NLS-1$
		if (queryService==null)
		   throw new ServletException(Messages.getString("Servlet.QueryServiceNotFound")); //$NON-NLS-1$
	}
	public List<TestDTO> getRecords(String sessionId) {

	    return this.queryService.getRecords(getCurrentUserId(), sessionId);
	    }
	/* (non-Javadoc)
	 * @see com.encon.projecttracker.rpc.Query#getCompanies(java.lang.String)
	 */
	public List<CompaniesDTO> getCompanies(String sessionId) {
		// TODO Auto-generated method stub
		return this.queryService.getCompanies(getCurrentUserId(), sessionId);
	}

	

}
